package com.alax.interfaces.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.alax.common.annotation.Log;
import com.alax.common.core.controller.BaseController;
import com.alax.common.core.domain.AjaxResult;
import com.alax.common.enums.BusinessType;
import com.alax.interfaces.domain.ApiCategory;
import com.alax.interfaces.service.IApiCategoryService;
import com.alax.common.utils.poi.ExcelUtil;
import com.alax.common.core.page.TableDataInfo;

/**
 * API分类Controller
 * 
 * @author alax
 * @date 2025-04-03
 */
@RestController
@RequestMapping("/interfaces/interfaceCategory")
public class ApiCategoryController extends BaseController
{
    @Autowired
    private IApiCategoryService apiCategoryService;

    /**
     * 查询API分类列表
     */
    // @PreAuthorize("@ss.hasPermi('interfaces:interfaceCategory:list')") // 暂时注释掉权限，允许所有登录用户访问
    @GetMapping("/list")
    public TableDataInfo list(ApiCategory apiCategory)
    {
        startPage();
        List<ApiCategory> list = apiCategoryService.selectApiCategoryList(apiCategory);
        return getDataTable(list);
    }

    /**
     * 导出API分类列表
     */
    @PreAuthorize("@ss.hasPermi('interfaces:interfaceCategory:export')")
    @Log(title = "API分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ApiCategory apiCategory)
    {
        List<ApiCategory> list = apiCategoryService.selectApiCategoryList(apiCategory);
        ExcelUtil<ApiCategory> util = new ExcelUtil<ApiCategory>(ApiCategory.class);
        util.exportExcel(response, list, "API分类数据");
    }

    /**
     * 获取API分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('interfaces:interfaceCategory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(apiCategoryService.selectApiCategoryById(id));
    }

    /**
     * 新增API分类
     */
    @PreAuthorize("@ss.hasPermi('interfaces:interfaceCategory:add')")
    @Log(title = "API分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ApiCategory apiCategory)
    {
        return toAjax(apiCategoryService.insertApiCategory(apiCategory));
    }

    /**
     * 修改API分类
     */
    @PreAuthorize("@ss.hasPermi('interfaces:interfaceCategory:edit')")
    @Log(title = "API分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ApiCategory apiCategory)
    {
        return toAjax(apiCategoryService.updateApiCategory(apiCategory));
    }

    /**
     * 删除API分类
     */
    @PreAuthorize("@ss.hasPermi('interfaces:interfaceCategory:remove')")
    @Log(title = "API分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(apiCategoryService.deleteApiCategoryByIds(ids));
    }
}
